﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace CalcSharp.MDIUI
{
    public partial class man_viewer : Form
    {
        public man_viewer()
        {
            InitializeComponent();
        }

        private void man_viewer_Load(object sender, EventArgs e)
        {
            this.qjump.Items.AddRange(manual.getdocumented());
            this.qjump.Sorted = true;
            this.qjump.AutoCompleteCustomSource.AddRange(manual.getdocumented());

            ArrayList firstchars = new ArrayList();
            string[] doc = manual.getdocumented();
            int i;
            ArrayList good = new ArrayList();
            for (i = 0; i < doc.Length; i++)
            {
                firstchars.Add(doc[i][0]);
            }
            firstchars.Sort();
            for (i = 0; i < firstchars.Count - 1; i++)
            {
                if (firstchars[i].ToString() != firstchars[i + 1].ToString())
                {
                    good.Add(firstchars[i]);
                }
            }
            firstchars.Clear();
            for (i = 0; i < good.Count; i++)
            {
                mantree.Nodes.Add(good[i].ToString(), good[i].ToString());
            }
            for (i = 0; i < doc.Length; i++)
            {
                try
                {
                    string key = doc[i][0].ToString();
                    mantree.Nodes[key].Nodes.Add(doc[i].ToString());
                }
                catch
                {
                    ;
                }
            }
            good.Clear();
            firstchars.Clear();
        }

        private void mantree_DoubleClick(object sender, EventArgs e)
        {
            if (mantree.SelectedNode != null)
            {
                string entry = mantree.SelectedNode.Text.ToString();
                if (entry.Length > 1)
                {
                    htmldisplay.Navigate(Application.StartupPath + @"\man.html");
                    this.Text = "Command Help - " + entry;
                    htmldisplay.DocumentText = manual.getManEntry(entry);
                }
            }
        }

        public void showman(string cmdname)
        {
            htmldisplay.Navigate(Application.StartupPath + @"\man.html");
            this.Text = "Command Help - " + cmdname;
            htmldisplay.DocumentText = manual.getManEntry(cmdname);
        }

        private void qjump_SelectedIndexChanged(object sender, EventArgs e)
        {
            htmldisplay.DocumentText = manual.getManEntry(qjump.Text);
        }
    }
}